# -*- encoding: utf-8 -*-
# @File    :   cmd.py
# @Time    :   2021/07/22 14:26:42
# @Author  :   wudongmin
# @Contact :   wudongmin@xroom.net
# @version   :  1.0

from uvicorn.main import run
from app import create_app
from app.model import Base
import uvicorn
import sys

app = create_app()


def run_server():
    # 启动服务
    uvicorn.run("cmd:app", host="0.0.0.0", port=9000, reload=True)


def create_database():
    # 创建数据库
    Base.metadata.create_all()


if __name__ == "__main__":
    if len(sys.argv) > 1:
        if sys.argv[1] == "runserver":
            run_server()
        elif sys.argv[1] == "createdb":
            create_database()
        else:
            print("无效参数")
    else:
        print(f"""runserver [启动服务]\ncreatedb [创建数据库]""")
